package vn.student.Adapter;

import static vn.student.database.DBComman.CONTENT;
import static vn.student.database.DBComman.TITLE;
import vn.student.database.SQLDataHelper;
import vn.student.notificationforandroid.R;
import android.app.Activity;
import android.database.Cursor;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Toast;

public class PageThongBao extends LinearLayout {

    LayoutInflater layoutInflater;
    View v;
    ListView mListView;
    AdapterThongBao mAdapterThongBao;
    final String TAG = "NAME COLUMN";
    Cursor c;

    public PageThongBao(final Activity context, SQLDataHelper mSQLHelp) {
	super(context);
	this.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
		LayoutParams.FILL_PARENT));
	layoutInflater = LayoutInflater.from(context);
	v = layoutInflater.inflate(R.layout.page_thongbao, null, true);
	this.addView(v, getLayoutParams());
	long row = mSQLHelp.insertThongBao("1", "Thong bao", "15/7/1990",
		"15/7/1990", "cong hoa xa hoi chu nghia viet nam", 0);
	Log.d(TAG, "vua them vao dong+" + row);
	c = mSQLHelp.getALLThongBao();
	context.startManagingCursor(c);
	mListView = (ListView) findViewById(android.R.id.list);
	mAdapterThongBao = new AdapterThongBao(context,
		R.layout.row_page_thongbao, c, new String[] { TITLE, 
			CONTENT }, new int[] { R.id.row_thongbao_title, R.id.row_thongbao_content });
	mListView.setAdapter(mAdapterThongBao);
	mListView.setOnItemLongClickListener(new OnItemLongClickListener() {

		public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
				int arg2, long arg3) {
			
			return false;
		}
	});
	mListView.setOnItemSelectedListener(new OnItemSelectedListener() {

		public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
				long arg3) {
			Toast.makeText(getContext(), "Touced", 1);
		}

		public void onNothingSelected(AdapterView<?> arg0) {
			// TODO Auto-generated method stub
			
		}
	});
    }

    public View getView() {
	return this;
    }

}
